<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 创建节点的构造函数
        const CreateDiv = function (html) {

            this.html = html;
            this.init();
        }

        // 对创建节点的行为进行拦截
        const ProxySingletonCreateDiv = (function () {

            let instance;

            return function (html) {
                if (!instance) {
                    instance = new CreateDiv(html);
                }

                return instance;
            }
        })();

        // 封装的创建节点的行为
        CreateDiv.prototype.init = function () {
            
            let div = document.createElement('div');
            div.innerHTML = this.html;
            document.body.appendChild(div);
        }



        let a = new ProxySingletonCreateDiv('this is a');
        let b = new ProxySingletonCreateDiv('this is b');

        console.log(a === b);
    </script>
</body>

</html>